package com.ruoyi.exam.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.exam.vo.ExamQuestionTagVo;
import com.ruoyi.exam.service.IExamQuestionTagService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 题目标签Controller
 *
 * @author Tellsea
 * @date 2025-05-30
 */
@Api(tags = "题目标签Controller")
@RestController
@RequestMapping("/exam/questionTag")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class ExamQuestionTagController extends BaseController {

    private final IExamQuestionTagService examQuestionTagService;

    @ApiOperation("查询题目标签列表")
    @PreAuthorize("@ss.hasPermi('exam:questionTag:list')")
    @GetMapping("/list")
    public TableDataInfo<ExamQuestionTagVo> list(ExamQuestionTagVo entity) {
        return examQuestionTagService.queryList(entity);
    }

    @ApiOperation("查询题目标签所有列表")
    @GetMapping("/listAll")
    public AjaxResult listAll(ExamQuestionTagVo entity) {
        return AjaxResult.success("查询成功", examQuestionTagService.queryAll(entity));
    }

    @ApiOperation("导出题目标签列表")
    @PreAuthorize("@ss.hasPermi('exam:questionTag:export')")
    @Log(title = "题目标签", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ExamQuestionTagVo entity) {
        List<ExamQuestionTagVo> list = examQuestionTagService.queryAll(entity);
        ExcelUtil<ExamQuestionTagVo> util = new ExcelUtil<>(ExamQuestionTagVo.class);
        util.exportExcel(response, list, "题目标签数据");
    }

    @ApiOperation("获取题目标签详细信息")
    @PreAuthorize("@ss.hasPermi('exam:questionTag:query')")
    @GetMapping(value = "/getInfo/{tagId}")
    public AjaxResult getInfo(@PathVariable("tagId") Long tagId) {
        return AjaxResult.success("查询成功", examQuestionTagService.queryById(tagId));
    }

    @ApiOperation("新增题目标签")
    @PreAuthorize("@ss.hasPermi('exam:questionTag:add')")
    @Log(title = "题目标签", businessType = BusinessType.INSERT)
    @PostMapping("add")
    public AjaxResult add(@RequestBody ExamQuestionTagVo entity) {
        return toAjax(examQuestionTagService.save(entity));
    }

    @ApiOperation("修改题目标签")
    @PreAuthorize("@ss.hasPermi('exam:questionTag:edit')")
    @Log(title = "题目标签", businessType = BusinessType.UPDATE)
    @PostMapping("edit")
    public AjaxResult edit(@RequestBody ExamQuestionTagVo entity) {
        return toAjax(examQuestionTagService.updateById(entity));
    }

    @ApiOperation("删除题目标签")
    @PreAuthorize("@ss.hasPermi('exam:questionTag:remove')")
    @Log(title = "题目标签", businessType = BusinessType.DELETE)
	@GetMapping("/remove/{tagIds}")
    public AjaxResult remove(@PathVariable Long[] tagIds) {
        return toAjax(examQuestionTagService.removeByIds(Arrays.asList(tagIds)) ? 1 : 0);
    }
}
